package com.zhejiangzhengyuan.municipal_common.utils;

import com.zhejiangzhengyuan.municipal_common.entity.File;
import com.zhejiangzhengyuan.municipal_common.mapper.FileMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

import static com.zhejiangzhengyuan.municipal_common.utils.excelFileUtils.FileUtil.getFilePo;

/** @author lin_ju Create on 2019/12/15 */
@Component
@Lazy
public class FileDuplicateCode {

  @Autowired private FileMapper fileMapper;

  public int updateFileDuplicateCode(File file, MultipartFile multipartFile, String module) {

    try {
      // 文件更新
      file = getFilePo(file, module, multipartFile);
      return fileMapper.updateById(file);
    } catch (IOException e) {
      e.printStackTrace();
      return 0;
    }
  }

  public int insertFileDuplicateCode(File file, MultipartFile multipartFile, String module) {
    try {
      file = getFilePo(file, module, multipartFile);
      return fileMapper.insert(file);
    } catch (IOException e) {
      e.printStackTrace();
      return 0;
    }
  }
}
